package com.link2room.rodimus.nmsrunner;

import com.aliyun.mns.model.Message;
import com.link2room.common.mns.Worker;
import com.link2room.common.util.JacksonUtil;
import com.link2room.rodimus.dto.param.api.MallOrderCancelParamDto;
import com.link2room.rodimus.facade.IMallApiFacadeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by LN on 2017/9/27.16:25
 */
@Component("mallOrderCancelRunner")
public class MallOrderCancelRunnerImpl implements Worker {

    @Resource
    private IMallApiFacadeService mallApiFacadeService;
    @Override
    public boolean exec(Message message) throws Exception {
        try {
            if(message.getDequeueCount() <= 1){
                String messageBody = message.getMessageBody();
                MallOrderCancelParamDto paramDto = JacksonUtil.jsonToBean(messageBody,MallOrderCancelParamDto.class);
                mallApiFacadeService.autoCancelOrder(paramDto);
                return true;
            }else {
                return true;
            }
        }finally {
            return true;
        }
    }
}
